/*
 * 文件名：ConsumableUseRecordTransation.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：wuliquan
 * 修改时间：2013-2-26
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.consumables.consumablesInfo.transaction.impl;

import org.springframework.beans.BeanUtils;

import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.dao.CommonDao;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.consumables.consumablesInfo.dao.ConsumablesReqRecordDao;
import com.wootide.cms.service.consumables.consumablesInfo.pojo.ConsumablesReqRecord;
import com.wootide.cms.service.consumables.consumablesInfo.transaction.ConsumablesReqRecordTransaction;

/**
 * 
 * 易耗品领用记录事务层实现
 * 〈功能详细描述〉
 * @author wuliquan
 * @version 2013-2-26
 * @see ConsumablesReqRecordTransationImpl
 * @since
 */
public class ConsumablesReqRecordTransationImpl implements
        ConsumablesReqRecordTransaction
{
    /**
     * 注入运行日志
     */
    private RunLog runLog;
    
    /**
     * 公共数据访问层实例
     */
    private CommonDao commonDao;
    
    /**
     * 易耗品数据访问层实例
     */
    private ConsumablesReqRecordDao consumablesReqRecordDao;
    
    
    public void addOneConsumablesReqRecord(
            ConsumablesReqRecord consumablesReqRecord)
    {
        // 打印方法入口参数
        runLog.debug("consumablesReqRecord=" + consumablesReqRecord);
        
        commonDao.addOneObject(consumablesReqRecord);
    }
    
    public ConsumablesReqRecord delOneConsumablesReqRecord(Integer innerIndex)
    {
        ConsumablesReqRecord oldConsumableUseRecord = consumablesReqRecordDao.findOneConsumablesReqRecordByReqRecordId(innerIndex);
        //判断要删除的记录是否存在
        if (null == oldConsumableUseRecord)
        {
            throw new CMSRuntimeException("consumableUseRecord not Exist!",
                    ErrorCodes.Consumables.ConsumablesInfo.COMSUMABLESINFO_NOTEXIST);
        }
        
        commonDao.delOneObject(oldConsumableUseRecord);
        
        return oldConsumableUseRecord;
    }
    
    public ConsumablesReqRecord modOneConsumablesReqRecord(
            ConsumablesReqRecord consumablesReqRecord)
    {
     // 打印方法入口参数
        runLog.debug("consumableUseRecord=" + consumablesReqRecord);
        ConsumablesReqRecord oldConsumablesReqRecord = consumablesReqRecordDao.findOneConsumablesReqRecordByReqRecordId(consumablesReqRecord.getId());
        
        //判断要修改的记录是否存在
        if (null == oldConsumablesReqRecord)
        {
            throw new CMSRuntimeException("ConsumableUseRecord not Exist!",
                    ErrorCodes.Consumables.ConsumablesReqRecord.COMSUMABLESREQRECORD_NOTEXIST);
        }
        
        //获取原始数据副本
        ConsumablesReqRecord oldConsumableReqRecordCopy = new ConsumablesReqRecord();
        BeanUtils.copyProperties(oldConsumablesReqRecord, oldConsumableReqRecordCopy);
        
        //修改易耗品信息
        oldConsumablesReqRecord.setConsumingDate(consumablesReqRecord.getConsumingDate());
        oldConsumablesReqRecord.setConsumingPeople(consumablesReqRecord.getConsumingPeople());
        oldConsumablesReqRecord.setConsumingPurpose(consumablesReqRecord.getConsumingPurpose());
        
        //便于日志记录
        return oldConsumableReqRecordCopy;
    }
    
    public QueryResults queryForPages(Page page, QueryCondition queryConditon)
    {
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        QueryResults queryResults = commonDao.queryForPages(page, queryConditon);
        return queryResults;
    }
    
    public ConsumablesReqRecord viewOneConsumablesReqRecord(Integer innerIndex)
    {
        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);
        ConsumablesReqRecord consumableUseRecord = consumablesReqRecordDao.findOneConsumablesReqRecordByReqRecordId(innerIndex);
        return consumableUseRecord;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    public void setCommonDao(CommonDao commonDao)
    {
        this.commonDao = commonDao;
    }

    public void setConsumablesReqRecordDao(
            ConsumablesReqRecordDao consumablesReqRecordDao)
    {
        this.consumablesReqRecordDao = consumablesReqRecordDao;
    }
}
